//
//  MementoAppDelegate.m
//  Memento 2.0
//
//  Created by Matt Toth on 10-07-04.
//  Copyright 2010 Team Memento. All rights reserved.
//
//  10-08-03: Add app foregrounding notification to refresh settings.  (C. Maddocks)
//  10-07-21: Bump version in header to 2.0.  (C. Maddocks)
//  10-07-04: Migrated from test project to version 1 project. (M. Toth)

#import "MementoAppDelegate.h"
#import "PhotoStackViewController.h"

@implementation MementoAppDelegate

@synthesize window;
@synthesize viewController;




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
	
	// Load default preferences
    [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Defaults" ofType:@"plist"]]];
	
	//check if phone is connect to the internet (must be for GPS to work)
	
	
	//added check to make sure GPS services are turned on - Matt
	CLLocationManager *manager = [[CLLocationManager alloc] init];
    if (manager.locationServicesEnabled == NO) {
        UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"Location services are turned off! You need to turn these on in your phone settings so Memento can store your memory locations." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [servicesDisabledAlert show];
        [servicesDisabledAlert release];
    }
    [manager release]; 
	
	return YES;
}

// When the application is about to terminate, save the photo collection (just the index information) to the filesystem.
// Note that the image and audio files have already been stored during memory capture; all we are storing here is the 
// PhotoCollection data structure that indexes these resources.
- (void)applicationWillTerminate:(UIApplication *)application {
	[viewController saveData];
}

// For iOS 4.0 devices, applicationWillTerminate: is seldom called because application can be "backgrounded".
// We still want to make sure our collection is moved to permanent storage in this case, though, so save anyway.
- (void)applicationDidEnterBackground:(UIApplication *)application {
	[viewController saveData];
}

// Again for iOS 4.0 devices, we want to make sure we refresh certain views (like the settings) when resuming from backgrounding.
- (void)applicationWillEnterForeground:(UIApplication *)application {
	[self.viewController.modalViewController viewWillAppear:NO];
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}

@end
